通过示例学SAS(10)

您所在的位置:网站首页 sas 创建表 通过示例学SAS(10)

通过示例学SAS(10)

#通过示例学SAS(10)| 来源: 网络整理| 查看: 265

1.Tabulate过程根据一个或多个分类变量,产生包括频数,百分比,均值等统计描述信息的表格。

一个简单的产生表格的例子是

title "All Defaults with One CLASS Variable"; proc tabulate data=blood;    class Gender;    table Gender; run;

class指明计算频数的类别变量,通常是字符型变量。table指明列在表格上的变量名,table后的变量名包含在必须在class指明的变量内。

制作串联表格

title "Demonstrating Concatenation"; proc tabulate data=learn.blood format=6.;     class Gender BloodType;     table Gender BloodType; run;

blood的频数统计接在性别频数统计的后面。

在table中插入逗号后,将产生二维表达。

title "Demonstrating Table Dimensions"; proc tabulate data=learn.blood format=6.;    class Gender BloodType;    table Gender,           BloodType; run;

若指定变量名形式为variable1*variable2,则将变量2嵌套在变量1中产生表格。如

title "Demonstrating Nesting"; proc tabulate data=learn.blood format=6.;        class Gender BloodType;        table Gender * BloodType; run;

对每一种性别,分别计算各种blood的频数。加入关键字ALL计算各变量的总频数。

2.对变量进行统计分析

proc tabulate也能计算变量的和或者平均值等统计量,并产生报告。例如

title "Specifying More than One Statistic"; proc tabulate data=learn.blood format=comma9.2;     var RBC WBC;     table (RBC WBC)*(mean min max); run;

当然也可以结合class对变量进行分类统计。如

title "Combining CLASS and Analysis Variables"; proc tabulate data=learn.blood format=comma11.2;    class Gender AgeGroup;    var RBC WBC Chol;    table (Gender ALL)*(AgeGroup All),           (RBC WBC Chol)*mean; run;

3.计算行和列的百分比

结合clss ,计算各分类变量的频数和百分比。例如

title "Counts and Percentages"; proc tabulate data=learn.blood format=6.;     class BloodType;     table BloodType*(n pctn); run;

关键字colpctn和rowpctn分别计算列和行百分比。若需计算行百分比,则加上关键字colpctn。

title "Percents on Column Dimension"; proc tabulate data=learn.blood noseps;     class Gender BloodType;     table (BloodType ALL='All Blood Types'),             (Gender ALL)*(n*f=5. colpctn*f=pctfmt7.1) /RTS=25;      keylabel All = 'Both Genders'                   n = 'Count'                   colpctn = 'Percent'; run;

另外一种需要计算百分比的是数字变量。使用关键字Pctsum.例如

title "Computing Percentages on a Numerical Value"; proc tabulate data=learn.sales;   class Region;   var TotalSales;   table (Region ALL),           TotalSales*(n*f=6. sum*f=dollar8.                           pctsum*f=pctfmt7.);   keylabel ALL = 'All Regions'                  n = 'Number of Sales'               sum = 'Average'             pctsum = 'Percent';   label TotalSales = 'Total Sales'; run;

如果以class指定了分类变量,则可以分别以colpctsum和rowpctsum统计列百分比和行百分比。

4.理解缺失值

注意:在class后指定的分类变量里,如果有一个观测值里含有缺失值,则此观测值会被从表格里除去。也就是说,不被统计在表格里面。

为了将缺失值也统计进去,加入关键字missing。例如

title "The Effect of Missing Values on CLASS variables"; proc tabulate data=learn.missing format=4. missing;    class A B;    table A ALL,B ALL; run;

缺失值会另外作为一种类别,列在表格里。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3